﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Reports.Menu
{
    public class Report2:DependencyObject
    {
        public static DependencyProperty StartDateProperty = DependencyProperty.Register("StartDate", typeof(DateTime), typeof(Report2));
        public DateTime StartDate
        {
            get { return (DateTime)GetValue(StartDateProperty); }
            set
            {
                SetValue(StartDateProperty, value);
            }
        }
        public static DependencyProperty EndDateProperty = DependencyProperty.Register("EndDate", typeof(DateTime), typeof(Report2));
        public DateTime EndDate
        {
            get { return (DateTime)GetValue(EndDateProperty); }
            set
            {
                SetValue(EndDateProperty, value);
            }
        }
        public static DependencyProperty TopProperty = DependencyProperty.Register("Top", typeof(int), typeof(Report2));
        public int Top
        {
            get { return (int)GetValue(TopProperty); }
            set
            {
                SetValue(TopProperty, value);
            }
        }
        public Report2()
        {
            EndDate = DateTime.Now;
            if (DateTime.Now.Month > 1)
                StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month - 1, DateTime.Now.Day);
            else StartDate = new DateTime(DateTime.Now.Year - 1, 12, DateTime.Now.Day);
            Top = 5;
        }
        public CrystalReport2 Load(TinyCinema.Bussiness.Login.Employee LoginInfo)
        {
            string sql = "select top " + Top + " THUCDON.MaTD, TenTD, DonGia, sum(SoLuong) as SoLuong" +
                         " from THUCDON, CTHDTD, HOADONTHUCDON" +
                         " where THUCDON.MaTD=CTHDTD.MaTD and HOADONTHUCDON.MaHDTD=CTHDTD.MaHDTD and NgayHDTD<='" + EndDate + "' and NGAYHDTD>='" + StartDate + "'" +
                         " group by THUCDON.MaTD, TenTD, DonGia"+
                         " order by SoLuong desc";


            CrystalReport2 report = new CrystalReport2();
            report.SetDataSource(TinyCinema.Data.Execution.Excute(sql));
            report.SetParameterValue("StartDate", StartDate);
            report.SetParameterValue("EndDate", EndDate);
            report.SetParameterValue("EmployeeName", LoginInfo.Emp.Name);
            report.SetParameterValue("Top", Top);
            return report;
        }
    }
}
